<template>
  <div>
    <van-button size="mini" type="info" @click="backHome">返回首页</van-button>
    <van-button size="mini" type="info" @click="backPrev">返回上一页({{ second }}s)</van-button>
  </div>
</template>

<script>
import './error.less';
import Vue from 'vue';
import {
    Button,
} from 'vant';

Vue.use(Button);

export default {
    name: 'backBtnGroup',
    data() {
        return {
            second: 5,
            timer: null,
        };
    },
    methods: {
        backHome() {
            this.$router.replace({
                name: 'home',
            });
        },
        backPrev() {
            this.$router.go(-1);
        },
    },
    mounted() {
        this.timer = setInterval(() => {
            if (this.second === 0) {
                clearInterval(this.timer);
                this.backPrev();
            } else this.second--;
        }, 1000);
    },
    beforeDestroy() {
        clearInterval(this.timer);
    },
};
</script>
